package org.fixed.dubboconsumer.controller;

import org.fixed.dubboconsumer.entity.InvokeVO;
import org.fixed.dubboconsumer.entity.ResourceDTO;
import org.fixed.dubboconsumer.entity.ResourceVO;
import org.fixed.dubboconsumer.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/consumer")
public class ConsumerController {

    @Autowired
    private ResourceService resourceService;

    /**
     * 获取方法列表
     * @param resourceVO
     * @return
     */
    @PostMapping(value = "/list")
    public ResponseEntity<ResourceDTO> list(@RequestBody ResourceVO resourceVO) throws Exception {
        return ResponseEntity.ok(resourceService.execute(resourceVO));
    }

    /**
     * 执行方法
     * @param invokeVO
     * @return
     */
    @PostMapping(value = "/invoke")
    public ResponseEntity invoke(@RequestBody InvokeVO invokeVO) throws Exception {
        Object result = resourceService.execute(invokeVO);
        return ResponseEntity.ok(null == result ? "{}" : result);
    }
}




